Crate env_id

source ·
Expand description

Use environment variables as identifiers.

Examples

let env_id!("CARGO_CRATE_NAME") = 1;
dbg!(env_id!("CARGO_CRATE_NAME"));

Or you can provide a default value:

let env_id!("HELLO" ?: hello) = 1;
dbg!(env_id!("HELLO" ?: hello));

This may be useful when you want to let users specify the name of a public item, but the following code doesn’t compile:

pub const env_id!("HELLO" ?: hello): usize = 1;

You can use another macro to do the same thing:

macro_rules! def_const {
  ($id:ident) => {
    pub const $id: usize = 1;
  };
}

env_id!("HELLO"?: hello => def_const);

Macros

  • Uses the given environment variable as an identifier.